package ticketmachine.logic.paymentAdapters;

import java.lang.reflect.InvocationTargetException;
import java.util.ResourceBundle;

import ticketmachine.logic.priceStrategies.IPriceCalculatorStrategy;
import ticketmachine.logic.priceStrategies.PriceCalculatorFactory;

public class PaymentFactory {
	private static PaymentFactory factory;
	private ResourceBundle configuration;
	
	public PaymentFactory(){
		try {
			configuration=ResourceBundle.getBundle("ticketmachine.configuration");
		} catch (Exception e) {
			System.out.println("Could not find Configuration File");
	}

	}

	public static PaymentFactory getInstance(){
		if (factory==null){
			factory=new PaymentFactory();
		}
		return factory;
	}

	public Payment getCashPayment(float amountDue, float amountIntroduced){
		String cashPaymentClass=configuration.getString("cashPaymentClass");;
		Payment p=null;
		try {
			p=(CashPayment)Class.forName(cashPaymentClass).getConstructor(float.class,float.class).newInstance(amountDue,amountIntroduced);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;
	}

	public Payment getCreditPayment(String cardNumber, String ExpiryDate, float amount){
		String creditPaymentClass=configuration.getString("creditPaymentClass");;
		Payment p=null;
		try {
			p = (CreditPayment)Class.forName(creditPaymentClass).getConstructor(String.class, String.class, float.class).newInstance(cardNumber, ExpiryDate, amount);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;
	}

        public Payment getDebitPayment(String pinNumber, String cardNbr, float amount){
		String debitPaymentClass=configuration.getString("debitPaymentClass");;
		Payment p=null;
		try {
			p = (DebitPayment)Class.forName(debitPaymentClass).getConstructor(String.class, String.class, float.class).newInstance(pinNumber, cardNbr, amount);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;
	}

        public Payment getECashPayment(String pin, float amount){
		String eCashPaymentClass=configuration.getString("eCashPaymentClass");;
		Payment p=null;
		try {
			p = (ECashPayment)Class.forName(eCashPaymentClass).getConstructor(String.class, float.class).newInstance(pin, amount);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;
	}
	
}
